<template>
	<view class="hexiaodetail">
		<headertop title="核销通道" :back1="back1"></headertop>
		<!-- 待核销 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11458@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==0">
		</image>
		<!-- 使用中 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11459@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==1">
		</image>
		<!-- 已完成 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11461@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==6">
		</image>
		<!-- 待退还 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11460@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==2"></image>


		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11460@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status!=0&&contentobj.status!=1&&contentobj.status!=6&&contentobj.status!=2">
		</image>

		<view class="centerbox"
			v-if="contentobj.status!=0&&contentobj.status!=1&&contentobj.status!=6&&contentobj.status!=2">
			<view class="statustext">
				{{statustext(contentobj.status)}}
			</view>
			<view class="centerboxtext">
				请检查核销码并核实订单信息，确认订单顺利完成。
			</view>
		</view>
		<!-- 待核销 -->
		<view class="centerbox" v-if="contentobj.status==0">
			<view class="statustext">
				待核销
			</view>
			<view class="centerboxtext">
				请检查核销码并核实订单信息，确认订单顺利完成。
			</view>
		</view>
		<!-- 使用中 -->
		<view class="centerbox" v-if="contentobj.status==1">
			<view class="statustext">
				使用中
			</view>
			<view class="centerboxtext">
				客户已领取设备正在使用中。
			</view>
		</view>
		<!-- 已完成 -->
		<view class="centerbox" v-if="contentobj.status==6">
			<view class="statustext">
				已完成
			</view>
			<view class="centerboxtext">
				服务已圆满结束！
			</view>
		</view>
		<!-- 待退还 -->
		<view class="centerbox" v-if="contentobj.status==2">
			<view class="statustext">
				待退还
			</view>
			<view class="centerboxtext">
				设备已按时归还核查无误后，及时办理押金退还。
			</view>
		</view>
		<view class="dingdaninfo" v-for="item in contentobj.goods" :key="item.id">
			<image :src="item.image" class="dingdaninfo_img" mode=""></image>
			<view class="dingdaninfo_rightbox">
				<view class="l1">
					<!-- 	<view class="gu" v-if="contentobj.type==3">
						固
					</view> -->
					<span>{{item.title}}</span>
				</view>
				<view class="l2">
					{{item.detail}}
				</view>
				<view class="jiage">
					￥{{item.price}}
				</view>
			</view>
		</view>
		<view class="yuyuebox" v-if="contentobj.type==3">
			<view class="center">
				<view class="title">
					<view class="st">

					</view>
					<span>预约信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						预约营位：
					</view>
					<span>{{contentobj.order.campfile}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						预约时间：
					</view>
					<span v-if="contentobj.type!=3"> {{contentobj.order.paytime_text}}</span>
					<span v-if="contentobj.type==3">
						{{contentobj.order.datetime}}（{{contentobj.order.starttime}}~{{contentobj.order.endtime}}）</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						预约人：
					</view>
					<span>{{contentobj.order.username}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						联系方式：
					</view>
					<span>{{contentobj.order.telphone}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						预约人数：
					</view>
					<span v-if="contentobj.type==3">{{contentobj.order.usernum}}</span>
					<span v-else>无</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						备注：
					</view>
					<span>{{contentobj.order.memo||'无'}}</span>
				</view>
			</view>
		</view>
		<!--已完成||使用中||待退还  -->
		<view class="yuyuebox" v-if="contentobj.type==2">
			<view class="center">
				<view class="title">
					<view class="st">
					</view>
					<span>租赁信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						租赁信息：
					</view>
					<span>{{contentobj.order.title}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						预约时间：
					</view>
					<span>{{contentobj.order.paytime_text}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						预约人：
					</view>
					<span>{{contentobj.order.username}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						联系方式：
					</view>
					<span>{{contentobj.order.telphone}}</span>
				</view>
			</view>
		</view>



		<view class="yuyuebox" v-if="contentobj.type==2">
			<view class="center">
				<view class="title">
					<view class="st">
					</view>
					<span>服务信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						服务类型：
					</view>
					<span>{{ydtypetext(contentobj.order.ydtype)}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						营位信息：
					</view>
					<span>{{contentobj.order.campfile}}</span>
				</view>
			</view>
		</view>

		<view class="yuyuebox" v-if="contentobj.type!=1">
			<view class="center">
				<view class="title">
					<view class="st">
					</view>
					<span>费用信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						{{contentobj.type==3?'场地费':'租赁费'}}：
					</view>
					<span>￥{{contentobj.order.price}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						押金：
					</view>
					<span>￥{{contentobj.order.deposit}}</span>
				</view>
			</view>
		</view>


		<view class="yuyuebox">
			<view class="center">
				<view class="title">
					<view class="st">
					</view>
					<span>支付信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						订单编号：
					</view>
					<span>{{contentobj.order.order_no}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						支付方式：
					</view>
					<span>{{contentobj.order.paytype==1?'微信支付':'余额支付'}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						下单时间：
					</view>
					<span>{{timestampfun(contentobj.order.createtime*1000)}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						支付时间：
					</view>
					<span>{{timestampfun(contentobj.order.paytime*1000)}}</span>
				</view>
				<!-- 已完成 -->
				<view class="linexinxi" v-if="contentobj.status==4">
					<view class="labletitle">
						核销时间：
					</view>
					<span>{{timestampfun(contentobj.order.tksqtime*1000)}}</span>
				</view>
			</view>
		</view>
		<view class="" style="height: 68rpx;">

		</view>
		<view class="" style="height: 184rpx;">

		</view>
		<view class="fixedbox" v-if="contentobj.status==2">
			<view class="centerbox" @click="show=true">
				退款
			</view>
		</view>
		<up-popup :show="show" mode="center">
			<view class="popucenter">
				<image src="/static/Frame@2x(6).png" class="close" @click="show=false" mode="">
				</image>
				<view class="title">
					请输入退款金额
				</view>
				<view class="inputbox">
					<input type="digit" v-model="money" placeholder="￥ 请输入退款金额" />
				</view>
				<view class="inputbox">
					<input type="text" v-model="memo" placeholder="请输入备注" />
				</view>
				<view class="btnss">
					<view class="btn1" @click="show=false">
						取消
					</view>
					<view class="btn2" @click="qd">
						确认
					</view>
				</view>
			</view>
		</up-popup>
	</view>
</template>

<script setup>
	import {
		orderfile,
		tuiya
	} from '@/api/my.js'
	import headertop from '@/components/header.vue'
	import {
		onPageScroll,
		onLoad
	} from "@dcloudio/uni-app";
	import {
		ref
	} from 'vue'
	const back1 = ref('')
	const show = ref(false)
	const money = ref('')
	const memo = ref('')
	const contentobj = ref({})
	onPageScroll((e) => {
		console.log(e, 'eeeeeeeeeeeeeee');
		if (e.scrollTop > 100) {
			back1.value = '#84BD78'
		} else {
			back1.value = ''
		}
	})
	onLoad((opt) => {
		init(opt.id)
	})
	async function qd() {
		if (!money.value) {
			uni.showToast({
				title: '请输入金额',
				icon: 'none'
			})
			return
		}
		uni.showModal({
			title: '提示', // 标题（可选）
			content: '确定要退款吗？', // 内容（可选）
			confirmText: '确定', // 确认按钮文字（可选，默认“确定”）
			cancelText: '取消', // 取消按钮文字（可选，默认“取消”）
			success: (res) => {
				if (res.confirm) {
					qd1()
					// 执行确定后的逻辑
				} else if (res.cancel) {
					console.log('用户点击了取消');
					// 执行取消后的逻辑
				}
			},
			fail: (err) => {
				console.error('弹窗调用失败', err);
			}
		});
	}
	async function qd1() {
		const res = await tuiya({
			id: contentobj.value.id,
			money: money.value,
			type: contentobj.value.type,
			memo: memo.value
		})
		if (res.data.code == 1) {
			uni.navigateBack()
			setTimeout(() => {
				uni.showToast({
					title: '确认成功'
				})
			}, 500)
			show.value = false
		} else {
			uni.showToast({
				title: res.msg,
				icon: "none"
			})
		}
	}

	function ydtypetext(num) {
		// 1：预订 2堂食类、3营位类 4自取类
		if (num == 1) {
			return '预订'
		} else if (num == 2) {
			return '堂食类'
		} else if (num == 3) {
			return '营位类'
		} else {
			return '自取类'
		}
	}
	async function init(id) {
		const res = await orderfile({
			id
		})
		if (res.data.code == 1) {
			contentobj.value = res.data.data
			console.log(contentobj.value, 'contentobj.valuecontentobj.valuecontentobj.value');
		}
	}

	function statustext(num) {
		if (num == 0) {
			return '待核销'
		} else if (num == 1) {
			return '使用中'
		} else if (num == 2) {
			return '待退还'
		} else if (num == 3) {
			return '可退押金'
		} else if (num == 4) {
			return '退款进行中'
		} else if (num == 5) {
			return '审核中'
		} else {
			return '已完成'
		}
	}

	function timestampfun(time) {
		const date = new Date(time);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, "0");
		const day = String(date.getDate()).padStart(2, "0");
		const hours = String(date.getHours()).padStart(2, "0");
		const minutes = String(date.getMinutes()).padStart(2, "0");
		const seconds = String(date.getSeconds()).padStart(2, "0");
		const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		return formattedDate;
	}
</script>
<style lang="scss">
	::v-deep .u-popup__content {
		background-color: rgba(255, 0, 0, 0) !important;
	}

	page {
		background: #F7F8FA;
	}

	.hexiaodetail {
		width: 100%;
		overflow: hidden;
		position: relative;

		.popucenter {
			width: 592rpx;
			height: 490rpx;
			background: linear-gradient(180deg, #F4FFF5 0%, #FFFFFF 31%);
			border-radius: 28rpx 28rpx 28rpx 28rpx;
			overflow: hidden;
			position: relative;

			.close {
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				top: 0%;
				right: 0%;
				margin-right: 24rpx;
				margin-top: 24rpx;
			}

			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #1D2129;
				text-align: center;
				margin-top: 48rpx;
				width: 100%;
				margin-bottom: 50rpx;
			}

			.btnss {
				width: 520rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: auto;

				.btn1 {
					width: 240rpx;
					height: 64rpx;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #7EBC79;
					text-align: center;
					line-height: 64rpx;
					font-weight: 400;
					font-size: 28rpx;
					color: #7EBC79;
				}

				.btn2 {
					width: 240rpx;
					height: 64rpx;
					background: #7EBC79;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					text-align: center;
					line-height: 64rpx;
					color: #FFFFFF;
					font-size: 28rpx;
				}
			}

			.inputbox {
				width: 520rpx;
				height: 84rpx;
				margin: auto;
				background: #F7F8FA;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				display: flex;
				align-items: center;
				margin-bottom: 30rpx;

				input {
					margin-left: 30rpx;
				}
			}
		}

		.fixedbox {
			width: 100%;
			height: 184rpx;
			background: #FFFFFF;
			box-shadow: 0rpx -4rpx 4rpx 0rpx rgba(0, 0, 0, 0.08);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			overflow: hidden;
			position: fixed;
			bottom: 0%;

			.centerbox {
				width: 686rpx;
				height: 88rpx;
				background: #7EBC79;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				text-align: center;
				line-height: 88rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				margin: 22rpx auto;
			}
		}

		&_back {
			width: 100%;
			height: 530rpx;
			position: absolute;
			z-index: -1;
		}

		.yuyuebox {
			width: 686rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.15);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			overflow: hidden;
			margin: auto;
			margin-top: 28rpx;

			.center {
				width: 630rpx;
				overflow: hidden;
				margin: auto;
				margin-top: 34rpx;

				.linexinxi {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #4E5969;
					display: flex;
					align-items: center;
					margin-bottom: 30rpx;

					.labletitle {
						width: 140rpx;
						color: #1D2129;
					}
				}

				.title {
					font-weight: bold;
					font-size: 32rpx;
					color: #1D2129;
					display: flex;
					align-items: center;
					margin-bottom: 28rpx;

					.st {
						width: 6rpx;
						height: 36rpx;
						background: #7EBC79;
						border-radius: 0rpx 24rpx 24rpx 0rpx;
						margin-right: 12rpx;
					}
				}
			}
		}

		.dingdaninfo {
			width: 686rpx;
			margin: auto;
			margin-top: 28rpx;
			overflow: hidden;
			background: #FFFFFF;
			height: 192rpx;
			display: flex;
			align-items: center;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.15);
			border-radius: 24rpx 24rpx 24rpx 24rpx;

			&_img {
				width: 162rpx;
				height: 144rpx;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin-left: 24rpx;
			}

			&_rightbox {
				margin-left: 20rpx;
				overflow: hidden;

				.l1 {
					display: flex;
					align-items: center;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #1D2129;

					.gu {
						width: 48rpx;
						height: 32rpx;
						background: #7EBC79;
						border-radius: 4rpx 16rpx 4rpx 16rpx;
						text-align: center;
						line-height: 32rpx;
						font-weight: 500;
						font-size: 24rpx;
						color: #FFFFFF;
						margin-right: 8rpx;
					}
				}

				.l2 {
					width: 412rpx;
					white-space: nowrap;
					/* 防止文本换行 */
					overflow: hidden;
					/* 隐藏超出容器的部分 */
					text-overflow: ellipsis;
					/* 超出部分显示为省略号 */
					margin-top: 20rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #868686;
				}

				.jiage {
					font-weight: bold;
					font-size: 36rpx;
					color: #7EBC79;
					margin-left: 294rpx;
					margin-top: 24rpx;
				}
			}
		}

		.centerbox {
			margin: auto;
			width: 686rpx;
			margin-top: 190rpx;
			overflow: hidden;

			.statustext {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 40rpx;
				color: #FFFFFF;
			}

			.centerboxtext {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-top: 14rpx;
			}
		}
	}
</style>